<?php
class Model_Store extends CI_Model
{
	
	function get_specific_all($num, $offset, $oneone, $keyarray)
	{
		
		
		$this->db->where($keyarray);
		
		$this->db->order_by($oneone);
		
		
		return $this->db->get('store', $num, $offset);
		
	}
	
	
	function get_specific_count_all($keyarray)
	{
		$this->db->from('store');
		
		
		
		$this->db->where($keyarray);

		
		return $this->db->count_all_results();
	}
	
	

		
	function addStore($data) {
		//$this->db->query("INSERT INTO " . $this->db->dbprefix . "store SET name = " . $this->db->escape($data['config_name']) . ", `url` = " . $this->db->escape($data['config_url']) . ", `ssl` = " . $this->db->escape($data['config_ssl']) . "");
		
		$this->db->query("INSERT INTO " . $this->db->dbprefix . "store SET name = " . $this->db->escape($data['config_name']). "");
		
		
		
		return $this->db->insert_id();
	}
	
	function editStore($store_id, $data) {
		//$this->db->query("UPDATE " . $this->db->dbprefix . "store SET name = " . $this->db->escape($data['config_name']) . ", `url` = " . $this->db->escape($data['config_url']) . ", `ssl` = " . $this->db->escape($data['config_ssl']) . " WHERE store_id = " . (int)$store_id . "");
		
		$this->db->query("UPDATE " . $this->db->dbprefix . "store SET name = " . $this->db->escape($data['config_name']) . " WHERE store_id = " . (int)$store_id . "");
						
		
	}
	
	function deleteStore($store_id) {
		
		$this->db->query("DELETE FROM " . $this->db->dbprefix . "store WHERE store_id = " . (int)$store_id );
		
		
		return $true;
	}	
	
	function getStore($store_id) {
		$query = $this->db->query("SELECT DISTINCT * FROM " . $this->db->dbprefix . "store WHERE store_id = " . (int)$store_id . "");
		
		return $query->row_array();
	}
	
	function getStores($data = array()) {
		
		
		$this->db->from('store');
		$this->db->order_by('url');

		$store_data = $this->db->get();
		
	 
		return $store_data->result_array();
	}

	function getTotalStores() {
      
		$this->db->from('store');	
		
		return $this->db->count_all_results();	
	}	
	
	function getTotalStoresByLayoutId($layout_id) {
      	$query = $this->db->query("SELECT COUNT(*) AS total FROM " . $this->db->dbprefix . "setting WHERE `key` = 'config_layout_id' AND `value` = " . (int)$layout_id . " AND store_id != '0'");
		
		return $query->row('total');		
	}
	
	function getTotalStoresByLanguage($language) {
      	$query = $this->db->query("SELECT COUNT(*) AS total FROM " . $this->db->dbprefix . "setting WHERE `key` = 'config_language' AND `value` = " . $this->db->escape($language) . " AND store_id != '0'");
		
		return $query->row('total');		
	}
	
	function getTotalStoresByCurrency($currency) {
      	$query = $this->db->query("SELECT COUNT(*) AS total FROM " . $this->db->dbprefix . "setting WHERE `key` = 'config_currency' AND `value` = " . $this->db->escape($currency) . " AND store_id != '0'");
		
		return $query->row('total');		
	}
	
	function getTotalStoresByCountryId($country_id) {
      	$query = $this->db->query("SELECT COUNT(*) AS total FROM " . $this->db->dbprefix . "setting WHERE `key` = 'config_country_id' AND `value` = " . (int)$country_id . " AND store_id != '0'");
		
		return $query->row('total');		
	}
	
	function getTotalStoresByZoneId($zone_id) {
      	$query = $this->db->query("SELECT COUNT(*) AS total FROM " . $this->db->dbprefix . "setting WHERE `key` = 'config_zone_id' AND `value` = " . (int)$zone_id . " AND store_id != '0'");
		
		return $query->row('total');		
	}
	
	function getTotalStoresByCustomerGroupId($customer_group_id) {
      	$query = $this->db->query("SELECT COUNT(*) AS total FROM " . $this->db->dbprefix . "setting WHERE `key` = 'config_customer_group_id' AND `value` = " . (int)$customer_group_id . " AND store_id != '0'");
		
		return $query->row('total');		
	}	
	
	function getTotalStoresByInformationId($information_id) {
      	$account_query = $this->db->query("SELECT COUNT(*) AS total FROM " . $this->db->dbprefix . "setting WHERE `key` = 'config_account_id' AND `value` = " . (int)$information_id . " AND store_id != '0'");
      	
		$checkout_query = $this->db->query("SELECT COUNT(*) AS total FROM " . $this->db->dbprefix . "setting WHERE `key` = 'config_checkout_id' AND `value` = " . (int)$information_id . " AND store_id != '0'");
		
		return ($account_query->row['total'] + $checkout_query->row['total']);
	}
	
	function getTotalStoresByOrderStatusId($order_status_id) {
      	$query = $this->db->query("SELECT COUNT(*) AS total FROM " . $this->db->dbprefix . "setting WHERE `key` = 'config_order_status_id' AND `value` = " . (int)$order_status_id . " AND store_id != '0'");
		
		return $query->row('total');		
	}	
	
}


?>